<template>
  <div class="rightBodyContent">
    <div class="rightBodyContent-in">
      <div class="tab-body mb-10">
        <div class="tab-box">
          <!--          // 0待审核1通过2驳回3借出4归还-->
          <el-radio-group v-model="radioStatus" size="small" @change="changeFn()">
            <el-radio-button label="all">全部({{ number ? number.all : 0 }})</el-radio-button>
            <el-radio-button :label="0">待审核({{ number ? number.apply : 0 }})</el-radio-button>
            <el-radio-button :label="3">已用章({{ number ? number.end : 0 }})</el-radio-button>
          </el-radio-group>
        </div>
        <div class="tab-box-list">

        </div>
      </div>
      <el-button size="small" type="primary" plain @click="addStudent" class="mb-10"><i class="el-icon-plus"></i>申请公章
      </el-button>
      <!--本体列表，数据 -->
      <div class="table-body">
        <div class="table-body-box">
          <el-table
              ref="multipleTable"
              :data="arryList"
              :stripe="tableStyle.tableStripe"
              :border="tableStyle.tableBorder"
              tooltip-effect="dark"
              header-cell-class-name="table-text-c"
              style="width: 100%">
                       <el-table-column
                           prop="name"
                           label="公章名称"
                           width="120"
                           align="center">
                           <template slot-scope="scope">
                             {{ scope.row.seal.name?scope.row.seal.name:'--' }}
                           </template>
                       </el-table-column>
            <el-table-column
                prop="purpose"
                label="用途"
                align="center">
            </el-table-column>
            <el-table-column
                label="用章日期"
                align="center"
                prop="time">
            </el-table-column>
            <el-table-column
                prop="remark"
                label="补充说明"
                align="center">
            </el-table-column>
            <el-table-column
                label="用章文件"
                align="center">
              <template slot-scope="scope">
                <!--                <el-button type="primary" plain @click="showFileFn(scope.row.file)" size="mini">查看用章文件</el-button>-->
                <el-popover
                    placement="left-start"
                    title="用章文件"
                    width="250"
                    trigger="click"
                    v-if="scope.row.file">
                  <div class="tableline-li">
                    <div class="list" v-for="(item,index) in scope.row.file" :key="index">
                      <preview_file :option="item" :index="`${index}${scope.row.id}`" @showImg="showImg"></preview_file>
                    </div>
                  </div>
                  <el-button slot="reference" type="primary" plain size="mini">查看用章文件</el-button>
                </el-popover>
              </template>
            </el-table-column>
            <el-table-column
                prop="return_time"
                label="盖章文件"
                align="center">
              <template slot-scope="scope">
                <!--                <viewerModle type="1" :imgSrc="scope.row.end_file" v-if="scope.row.end_file"></viewerModle>-->
                <ImagePreview :src="scope.row.end_file" width="40px" height="40px"></ImagePreview>
              </template>
            </el-table-column>
            <el-table-column
                prop="status"
                label="状态"
                align="center">
              <template slot-scope="scope">
                <!--          0待审核1通过2驳回3完成 -->
                <span v-if="scope.row.status==0">待审核</span>
                <span v-if="scope.row.status==1">已通过</span>
                <span v-if="scope.row.status==2" class="examinBtn">已驳回 <i @click="shoeExaminFn(scope.$index)">查看驳回说明</i></span>
                <span v-if="scope.row.status==3">已用章</span>
              </template>
            </el-table-column>
            <el-table-column
                label="操作"
                align="center"
                width="90">
              <template slot-scope="scope">
                <el-button v-if="scope.row.status==0" type="danger" plain size="small" @click="deleteList(scope.$index)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <!--工具条 分页-->
      <el-col :span="24" class="toolbar">
        <el-pagination
            background
            layout="total, prev, pager, next"
            :total="page.total"
            :page-size="page.pagesize"
            @current-change="handleSizeChange">
        </el-pagination>
      </el-col>
    </div>
    <applyLicence :visible.sync="detailVisible" @InitFn="InitFn" :sealId="sealId"></applyLicence>
    <!--    预览-->
    <div style="position: fixed;top: -9999px">
      <viewer :images="studentPhoto" class="descimgBox">
        <img :src="studentPhoto[0]" class="viewerImg" ref="imgPrive">
      </viewer>
    </div>
  </div>
</template>

<script>
import {pagination, tableoption} from '@/utils/util.js'
import applyLicence from "./applyLicence";
import {sealApplyDelete} from '@/api/admin/badge'
import {mapGetters} from "vuex";

export default {
  components: {
    applyLicence,
  },
  data() {
    return {
      studentPhoto: [],
      radioStatus: 'all',
      detailVisible: false,
      licenceId: 0,
      handleSelection: [],
      arryList: [], // 页面数据列表
      // 设置table样式
      tableStyle: tableoption,
      // 设置table页面分页所需
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      indexOption: '',
      classesListNew: [],
      sectionList: [],
      classesList: [],
      // 搜索组件
      searchForm: {},
      parentsVisible: false,
      parentsOption: '',
      HttpUrl: '',
      sealId: 0,
      number: null
    }
  },
  computed: {
    ...mapGetters(['userInfo']),
  },
  created() {
    this.InitFn();
  },
  methods: {
    showImg(option) {
      console.log('option:', option)
      this.$set(this.studentPhoto, 0, option[0])
      setTimeout(() => {
        this.$refs.imgPrive.click()
      }, 100)
    },
    // 初始化
    InitFn() {
      // 0待审核1通过2驳回3借出4归还
      let option_ = {p: this.page.pageindex, user_id: this.userInfo.id}
      if (this.radioStatus !== 'all') {
        option_.status = this.radioStatus;
      }
      this.$fetch(this.api.seal.apply_list, option_).then((response) => {
        if (response.code === 0) {
          for (let item of response.list.data) {
            if (item.file) {
              if (item.file.indexOf('[') !== -1) {
                if (item.file !== '[]') {
                  item.file = JSON.parse(item.file)
                }
              } else {
                item.file = JSON.parse(JSON.stringify([{name: '文件1', src: item.file}]))
              }
            }
          }
          this.arryList = JSON.parse(JSON.stringify(response.list.data))
          this.page.total = response.list.total
          this.number = response.number
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    changeFn() {
      this.InitFn()
    },
    shoeExaminFn(index) {
      this.$confirm(this.arryList[index].content, '驳回说明', {
        confirmButtonText: '重新申请',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // :visible.sync="detailVisible" @InitFn="InitFn" :sealId="sealId"
        this.sealId = this.arryList[index].id;
        this.detailVisible = true;
      }).catch(() => {
      })
    },
    // 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    // 搜索组件
    searchFn(option) {
      this.page.pageindex = 1
      this.searchForm = option
      this.InitFn()
    },
    addStudent(row) {
      this.licenceId = row || '';
      this.detailVisible = true;
    },
    deletWx(index) {
      let n = this;
      this.$confirm('确认解除' + this.arryList[index].name + '微信绑定, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.closeBinding(index, n.arryList[index].id)
      }).catch(() => {
      })
    },
    closeBinding(index, id) {
      let n = this;
      this.$post(this.api.patents.closeWxBind, {id: id}).then((response) => {
        if (response.code === 0) {
          n.arryList[index].openid = ''
          this.$message({
            type: 'success',
            message: '解绑成功!'
          })
        } else {
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    deleteList(index) {
      let this_ = this
      this.$confirm('此操作将删除 ' + (this.arryList[index].licence ? this.arryList[index].licence.name : '') + ' 用章申请, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        closeOnClickModal: false,
        type: 'warning'
      }).then(() => {
        this_.deletFn(index)
      }).catch(() => {
      })
    },
    deletFn(index) {
      sealApplyDelete({id: this.arryList[index].id}).then(res => {
        console.log('res:', res)
        if (!res.code) {
          this.$message.success(res.msg)
          this.InitFn()
        }
      })
    },
  },
  mounted() {
  },
}
</script>

<style scoped>

.wx-user-box-line img {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  margin-right: 5px;
}

.wx-user-box-line {
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-wx {
  cursor: pointer;
  padding: 5px;
}

.btn-wx:hover {
  color: #1b8de5;
  text-decoration: underline;
}

.delet-wx {
  color: red;
  cursor: pointer;
}

.delet-wx:hover {
  text-decoration: underline;
}

.tab-body {
  display: flex;
  align-items: center;
}

.tab-box {
  flex: 1;
}

.examinBtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: red;
}

.examinBtn i {
  font-style: normal;
  color: #1b8de5;
  cursor: pointer;
  font-size: 12px;
}
</style>
